package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Lists;

import java.util.List;
import java.util.Objects;

/**
 * 用户订单操作定义
 */
public enum UserOrderActionEnum implements IEnum<String> {

    CANCEL("cancel", "取消订单", "取消订单", Lists.asList(UserOrderStatusEnum.NEW_ORDER,UserOrderStatusEnum.WAIT_CHECK,UserOrderStatusEnum.WAIT_DELIVERY,UserOrderStatusEnum.WAIT_VISIT,UserOrderStatusEnum.WAIT_ACCEPT,UserOrderStatusEnum.WAIT_CONFIRM,UserOrderStatusEnum.WAIT_RECEIVE), UserOrderStatusEnum.CANCELLED, Boolean.FALSE),
    AGAIN("again", "重新估价", "重新估价", Lists.asList(UserOrderStatusEnum.CANCELLED,UserOrderStatusEnum.CLOSED), null, Boolean.FALSE),
    ;

    private String actionCode;

    /**
     * 操作名称
     */
    private String actionName;

    /**
     * 操作展示名称
     */
    private String actionText;

    /**
     * 执行操作的前置订单状态
     */
    private List<UserOrderStatusEnum> fromOrderStatus;

    /**
     * 执行操作后的流转订单状态(为空则无状态变更)
     */
    private UserOrderStatusEnum toOrderStatus;

    /**
     * 额外的条件(初当前订单状态 && 额外条件)
     */
    private Boolean moreCondition;

    UserOrderActionEnum(String actionCode, String actionName) {
        this.actionCode = actionCode;
        this.actionName = actionName;
    }

    UserOrderActionEnum(String actionCode, String actionName, String actionText, List<UserOrderStatusEnum> fromOrderStatus, UserOrderStatusEnum toOrderStatus, Boolean moreCondition) {
        this.actionCode = actionCode;
        this.actionName = actionName;
        this.actionText = actionText;
        this.fromOrderStatus = fromOrderStatus;
        this.toOrderStatus = toOrderStatus;
        this.moreCondition = moreCondition;
    }

    public static String getDesc(Integer actionCode) {
        for (UserOrderActionEnum thisEnum : UserOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的订单操作[{}]", actionCode);
    }

    public static String get(String actionCode) {
        for (UserOrderActionEnum thisEnum : UserOrderActionEnum.values()) {
            if (Objects.equals(thisEnum.actionCode, actionCode)) {
                return thisEnum.actionName;
            }
        }
        throw Ex.systemError("未定义的订单操作[{}]", actionCode);
    }

    @Override
    public String value() {
        return this.actionCode;
    }

    @Override
    public String named() {
        return this.actionName;
    }

    public String getActionCode() {
        return actionCode;
    }

    public String getActionName() {
        return actionName;
    }

    public String getActionText() {
        return actionText;
    }

    public List<UserOrderStatusEnum> fromOrderStatus() {
        return fromOrderStatus;
    }

    public UserOrderStatusEnum toOrderStatus() {
        return toOrderStatus;
    }

    public Boolean moreCondition() {
        return moreCondition;
    }
}
